package com.thghh.graph;

import com.thghh.ch3.list.ArrayList;
import com.thghh.ch3.list.List;

/**
 * 图
 *
 * @author pengzhikang
 * @date 2024/8/19 14:31
 * @since 1.0.0
 */
public class Graph {

    /** 顶点列表 */
    private List<Integer> vertexList;

    /** 边缘 */
    private int[][] edges;

    /** 边数 */
    private int numOfEdges;

    public Graph(int n) {
        // 初始化顶点列表
        vertexList = new ArrayList<>(n);
        edges = new int[n][n];
        numOfEdges = 0;
    }

    public int getNumOfVertex() {
        return vertexList.length();
    }

    public int getNumOfEdges() {
        return  numOfEdges;
    }

    public int getWeight(int v1, int v2) {
        return  edges[v1][v2];
    }

    public void insertVertex(int v1, int v2, int weight) {
        this.edges[v1][v2] = weight;
        this.numOfEdges++;
    }

}
